import React from 'react';
import { FormPanel, FormPanelBtnAlign, type FormPanelObject } from 'lfun-bg-comp';
import { Modal } from 'antd';
import { GRADUATION_STATUS } from '@/constant/studentOptions';
import { StuGraduationSrv } from '@/service/student';

const Settings: React.FC<{ show: boolean; onChange: Function; formValue: any }> = ({
  show,
  onChange,
  formValue = {},
}) => {
  const list = [
    {
      title: '',
      labelCol: { span: 4 },
      wrapperCol: { span: 20 },
      span: 24,
      inputs: [
        {
          label: '申请学生',
          name: 'student_name',
          key: 'student_name',
          required: true,
          disabled: () => true,
          textRange: [0, 20],
        },
        {
          label: '毕业状态',
          name: 'status',
          key: 'status',
          required: true,
          inputType: 'select',
          span: 24,
          renderOption: GRADUATION_STATUS,
        },
        // {
        //   label: '备注',
        //   name: 'graduate_remark',
        //   key: 'graduate_remark',
        //   required: false,
        //   inputType: 'textarea',
        //   span: 24,
        //   textRange: [0, 200],
        // },
      ],
    },
  ];

  const onSubmit = async (formPanelObject: FormPanelObject) => {
    const values = formPanelObject.getFieldsValue();
    const params = {
      student_id: formValue?.student_id,
      ...values,
      // graduation_type: values.graduation_type || '',
      // graduate_remark: values.graduate_remark || '',
    };
    console.log('🚀 ~ onSubmit ~ params:', params);
    // 保存逻辑
    const res = await StuGraduationSrv.graduate(params);
    console.log('🚀 ~ onSubmit ~ res:', res);
    if (res.success) {
      formPanelObject.resetFields();
      onChange(true);
    }
  };

  return (
    <>
      <Modal title="设定" width="50%" footer={[]} open={show} onCancel={() => onChange()}>
        <FormPanel
          btnsAlign={FormPanelBtnAlign.center}
          restBtnText="返回"
          submitBtnText="确定"
          values={formValue}
          onFinish={(formPanelObject: FormPanelObject) => {
            onSubmit(formPanelObject);
            return false;
          }}
          onReset={() => onChange()}
          template={list}
        />
      </Modal>
    </>
  );
};

export default Settings;
